import React from 'react'
// ===================================================================== Temp
import Table from '#cpt/temp/Table'
import Delete from '#cpt/temp/Delete'
// ===================================================================== Declare
const { $Lazy, $fn, $http } = window
// ===================================================================== Lazy
const Button 			= $Lazy.load(()=>import('@antd/button'))
// ===================================================================== component

class Index extends React.Component{
	state = {
		data: [],
		selectedKeys: []
	}

	fetch = () => $fn.fetch.call(this,'qc-lot/index', {param: {enabled: 2}})
	
	// 表单
	cols = [
		{ title: '批号',				dataIndex: 'master_lot_number', 	width:100 },
		{ title: '控制品名称', 		dataIndex: 'control_name', 			width:200 },
		{ title: '有效期', 			dataIndex: 'expiration_date', 		...$fn.table.time },
		{ title: '水平', 			dataIndex: 'levels', 				width:40 },
		{ title: '基质', 			dataIndex: 'matrix', 				width:200 },
		{ title: '厂商', 			dataIndex: 'manufacturer', 			width:200 },
	]
	
	btns = () => [
		{label: '打开分析批', onClick: () => {
			$http.submit(null, 'qc-lot/open', { param: {uuid: this.state.selectedKeys[0]}}).then(() => {
				this.fetch()
				this.props.refresh()
				$fn.msg.success('打开分析批成功')
			})
		}, disabled: !this.state.selectedKeys.length },
		Delete.call(this, 'qc-lot/del', { param: {uuid: this.state.selectedKeys[0]}, isKeys: 1 })
	]
	
	render(){
		return <div className='ex fx pt5'>
			<div className='ex fx' style={{marginLeft: -10}}>
				{ Table.call(this, { type: 1 }) }
			</div>
			<div className='fv'>
				{
					this.btns().map((v,i)=> <Button
							key			= { i } 
							style		= { {minWidth:60} } 
							disabled	= { v.disabled } 
							loading		= { v.loading } 
							label		= { v.label } 
							onClick		= { v.onClick } 
							className	= 'mb10' 
							ghost
						/>
					)
				}
			</div>
		</div>
	}
}

export default Index